** This file is to replicate 
** Graham, Kim, Tavits, and Ward ``How Economic Integration Affects Party Issue Emphases". 
** Comparative Political Studies, XX(X):XX-XX, Forthcoming.
** SI.4 "Long-Term Effects: Dynamic Simulation"

*** First, download "dynism.ado" file from Laron Williams' website (http://web.missouri.edu/~williamslaro/research.html)

*** Set up the working directory with the "cd" command
cd ".."

* Load the "dynsim" command
do "dynsim.ado"

*** Install Clarify package
net from http://gking.harvard.edu/clarify/
net install clarify

*** Load cmp data:
use "Country_level.dta", clear
set more off

*** Figure SI.4.1
* Create lag_unweighted_nonecon
sort country_code election_count
by country_code: gen lag_unweighted_nonecon = unweighted_nonecon[_n+1] if election_count==election_count[_n+1]-1

reg unweighted_nonecon kof_glob_econ Religiosity2 Ethnic_frac_Alesina enep gdp_growth_wdi pop_pwt gini_market_swiid advanced
qui estsimp regress unweighted_nonecon lag_unweighted_nonecon kof_glob_econ Religiosity2 Ethnic_frac_Alesina enep gdp_growth_wdi pop_pwt gini_market_swiid advanced, sims(1000)
	

* Dynamic simulation
dynsim, ldv(lag_unweighted_nonecon) /*
*/	scen1(mean)  /*
*/	scen2(lag_unweighted_nonecon mean kof_glob_econ 48.28 Religiosity2 mean Ethnic_frac_Alesina mean enep mean gdp_growth_wdi mean pop_pwt mean gini_market_swiid mean advanced mean)  /*
*/	scen3(lag_unweighted_nonecon mean kof_glob_econ 81.12 Religiosity2 mean Ethnic_frac_Alesina mean enep mean gdp_growth_wdi mean pop_pwt mean gini_market_swiid mean advanced mean)  /*
*/	n(8) sig(95) sav(dynism_2)

* Graph it
preserve
use dynism_2.dta, clear
keep if t!=0 
	twoway (rcapsym lower_3 upper_3 t, msymbol(sh)) (rcapsym lower_1 upper_1 t, msymbol(x)) (rcapsym lower_2 upper_2 t, msymbol(s)), ytitle("Politicization of non-economic issues", size(smallmedium)) /*
	*/ legend(label(1 "Mean+SD Globalization") label(2 "Mean Globalization") label(3 "Mean-SD Globalization") col(1)) /*
	*/ xtitle("Election", size(medium)) xlabel(1(2)8) graphregion(color(white)) bgcolor(white)
restore


*** Figure SI.4.2
* Load cmp data:
use "Country_level.dta", clear
set more off

* Create lag_unweighted_nonecon
sort country_code election_count
by country_code: gen lag_unweighted_nonecon = unweighted_nonecon[_n+1] if election_count==election_count[_n+1]-1

reg unweighted_nonecon EU_pc_econ_B Religiosity2 Ethnic_frac_Alesina enep gdp_growth_wdi pop_pwt gini_market_swiid advanced
qui estsimp regress unweighted_nonecon lag_unweighted_nonecon EU_pc_econ_B Religiosity2 Ethnic_frac_Alesina enep gdp_growth_wdi pop_pwt gini_market_swiid advanced, sims(1000)

* Dynamic simulation
dynsim, ldv(lag_unweighted_nonecon) /*
*/	scen1(mean)  /*
*/	scen2(lag_unweighted_nonecon mean EU_pc_econ_B -3.04 Religiosity2 mean Ethnic_frac_Alesina mean enep mean gdp_growth_wdi mean pop_pwt mean gini_market_swiid mean advanced mean)  /*
*/	scen3(lag_unweighted_nonecon mean EU_pc_econ_B 10.68 Religiosity2 mean Ethnic_frac_Alesina mean enep mean gdp_growth_wdi mean pop_pwt mean gini_market_swiid mean advanced mean)  /*
*/	n(8) sig(95) sav(dynism_3)

* Graph it
preserve
use dynism_3.dta, clear
keep if t!=0
	twoway (rcapsym lower_3 upper_3 t, msymbol(sh)) (rcapsym lower_1 upper_1 t, msymbol(x)) (rcapsym lower_2 upper_2 t, msymbol(s)), ytitle("Politicization of non-economic issues", size(smallmedium)) /*
	*/ legend(label(1 "Max European Integration") label(2 "Mean European Integration") label(3 "Min European Integration") col(1)) /*
	*/ xtitle("Election", size(medium)) xlabel(1(2)8) graphregion(color(white)) bgcolor(white)
restore
